package io.renren.modules.cardeal.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSONObject;
import io.renren.common.utils.PageData;
import io.renren.common.utils.R;
import io.renren.modules.carcustomerinfo.vo.CarCustomerInfoVO;
import io.renren.modules.cardeal.dto.CarDealDTO;
import io.renren.modules.cardeal.vo.CarDealVO;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import io.renren.modules.cardeal.entity.CarDealEntity;
import io.renren.modules.cardeal.service.CarDealService;




/**
 * 车辆成交表
 *
 */
@RestController
@RequestMapping("/cardeal")
public class CarDealController {
    @Autowired
    private CarDealService carDealService;

    /**
     * 车辆成交表(分页)
     */
    @ApiOperation("车辆成交表(分页)")
    @GetMapping("/list")
    public R list(@RequestParam Map<String, Object> params){
        PageData<CarDealVO> pageData = carDealService.queryCarDealPage(params);
        return R.ok().put("page", pageData);
    }

    /**
     * 销售业绩统计
     */
    @ApiOperation("销售业绩统计")
    @GetMapping("/performance")
    public R performance(@RequestParam Map<String, Object> params){
        List<JSONObject> jsonObjectList = carDealService.performance(params);
        return R.ok().put("jsonObjectList", jsonObjectList);
    }

    /**
     * 添加车辆成交
     */
    @ApiOperation("添加车辆成交")
    @PostMapping("/add")
    public R addCarDeal(@RequestBody CarDealDTO dto){
        carDealService.addCarDeal(dto);
        return R.ok();
    }

    /**
     * 财务统计
     */
    @ApiOperation("财务统计")
    @GetMapping("/caiwu")
    public R caiwu(@RequestParam Map<String, Object> params){
        JSONObject json = carDealService.caiwu(params);
        return R.ok().put("json", json);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions(":cardeal:info")
    public R info(@PathVariable("id") Long id){
		CarDealEntity carDeal = carDealService.getById(id);

        return R.ok().put("carDeal", carDeal);
    }



    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions(":cardeal:update")
    public R update(@RequestBody CarDealEntity carDeal){
		carDealService.updateById(carDeal);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions(":cardeal:delete")
    public R delete(@RequestBody Long[] ids){
		carDealService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
